package com.example.mpchartlibtest;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.utils.XLabels.XLabelPosition;

public class MainActivity extends Activity {

	private LineChart lineChart;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initView();
		initChart();
	}

	private void initChart() {
		// TODO Auto-generated method stub
//		String[] temp = { "单位：小时", "8月\n2015", "9月\n2015" , "10月\n2015" , "11月\n2015" , "12月\n2015", "1月\n2016" , "2月\n2016"};
		String[] temp = { "单位：小时", "8月", "9月" , "10月" , "11月" , "12月", "1月" , "2月"};
		ArrayList<Entry> yVals = new ArrayList<Entry>() ;
		Entry entry = null ;
		for (int i = 0; i < temp.length ; i++) {
			entry = new Entry((float)(Math.random() * 100), i) ;
			yVals.add(entry) ;
		}
		LineDataSet lineDataSet = new LineDataSet(yVals, "数值") ;
		LineData data = new LineData(temp , lineDataSet);
		lineChart.setData(data);
		lineChart.getXLabels().setPosition(XLabelPosition.BOTTOM);
	}

	private void initView() {
		// TODO Auto-generated method stub
		lineChart = (LineChart) findViewById(R.id.lineChart);
	}

}
